<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="java.util.List"%>
<%@ page import="tt.love.hw.jdo.User"%>

<html>
<head>
<meta charset="utf-8">
<title>COLAS</title>


<!-- blueprint -->
<link rel="stylesheet" href="/css/screen.css" type="text/css"
	media="screen, projection">
<link rel="stylesheet" href="/css/print.css" type="text/css"
	media="print">

<link rel="stylesheet" href="/css/ie.css" type="text/css" media="screen, projection">

<!-- custom css -->
<link rel="stylesheet" href="/css/datatable.css" type="text/css"
	media="screen" />
<link rel="stylesheet" href="/css/bp_custom.css" type="text/css"
	media="screen" />


</head>
<body>
<!-- userbar -->
<div id="userbar" class="container">
<div id="nav">
<ul>
	<li><span>Couple Registration</span></li>
</ul>
</div>
</div>


<!-- main -->
<div id="main" class="container">



<div id="content" class="span-19 last"><!-- content -->
<hr class="space" />


<div id="content_wrapper" class="span-19 last">
<div class="content_message">
<div class="box"></div>
</div>
<div class="content_body">
<div class="box">
<form class="inline" action="/admin/listUser" method="post">
<fieldset><legend></legend>

<div class="span-17 last"><span class="span-2"> <label>User
ID</label> </span> <span class="span-7"> <input type="text" class="text span-6"
	value="" name="userId" /> </span></div>

<div class="span-17 last"><span class="span-2"> <label>Name</label>
</span> <span class="span-7"> <input type="text" class="text span-6"
	value="" name="userName" /> </span></div>

<!-- form row2 -->
<div class="span-17 last"><span
	class="prepend-2 span-7 append-8 last"> <input type="submit"
	value="View" class="button_prime" /> <input type="button"
	value="Add User" class="button_second"
	onclick="window.location='/admin/user_create.jsp'" /> </span></div>


</fieldset>
</form>

<div>
<%
                                          List<User> resultUsers = (List<User>) request.getAttribute("resultUsers");
                                          if (resultUsers!=null && !resultUsers.isEmpty()){
                         %>
<table id="tdata1" cellspacing="0" cellpadding="0" border="0"
	width="100%">
	<thead>
		<tr>
			<th>User ID</th>
			<th>Name</th>
			<th>Husband/Wife?</th>
			<th>Mate Id</th>
			<th>&nbsp;</th>
		</tr>
	</thead>
	<tbody>
		<%
                                          for(User user: resultUsers){
                                %>

		<tr>
			<td><%=user.getUserId()%></td>
			<td><%=user.getUserName()%></td>
			<td><%=user.getRole()%></td>
			<td><%=user.getMateUserId()%></td>
			<td><a class="ico_user_delete" title="Delete User"
				href="javascript:void(0)"
				onClick="deleteUser('<%=user.getUserId()%>','<%=user.getMateUserId()%>');"></a></td>
		</tr>
		<%
                                 }
                                 %>
	</tbody>
</table>
<%
                                 } else {
                               %> No users found. <%
                                 }
                                 %>
</div>
</div>
</div>
</div>
</div>
</div>




<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/jquery.dataTables.js"></script>
<script type="text/javascript">
		$(function(){
			var tdata1;
			
			// datatable
			tdata1 = $('#tdata1').dataTable({
				"sPaginationType": "full_numbers",
				"bFilter": true,
				'iDisplayLength': 4,
				"aoColumnDefs": [ 
                    { "bSortable": true, "aTargets": [ 2 ], "sClass": "center_text", "sWidth": "110px" },
					{ "bSortable": false, "aTargets": [ 4 ], "sClass": "center_text", "sWidth": "22px" }
				]
			});
			
			// init
			$('#tdata1_filter').hide();
		});
		function deleteUser(duserid,dmateuserid,dcoupleid){
		    var deleteForm = document.createElement("form");  
		    document.body.appendChild(deleteForm); 
		    deleteForm.method="post";　
		    var　userId　=　document.createElement("input");　
		   　userId.type="hidden";　
		   　userId.name="userId";　　
		   　userId.value=duserid;
		   deleteForm.appendChild(userId); 
		   var　mateUserId　=　document.createElement("input");　
		   　mateUserId.type="hidden";　
		   　mateUserId.name="mateUserId";　　
		   　mateUserId.value=dmateuserid;
		   deleteForm.appendChild(mateUserId); 
		    //deleteForm.action="/deleteUser?userId="+duserid+"&mateUserId="+dmateuserid+"&coupleId="+dcoupleid;
		    deleteForm.action="/admin/deleteUser";
		    deleteForm.submit();  
		}
		
	</script>
</body>
</html>